package com.santu.edu.supporter.biz.order.kd.pojo.vo;

import cn.hutool.core.collection.CollUtil;
import com.santu.edu.supporter.biz.order.kd.pojo.dto.KdOrderDTO;
import com.santu.edu.supporter.util.PageData;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author luoyaoqi
 * @createTime 2024/3/7
 * @description
 */
@Data
@Accessors(chain = true)
public class KdOrderVO {

    /**
     * 订单号
     */
    private String orderId;

    /**
     * 快递点id
     */
    private String buildingsId;

    /**
     * 购买的商品信息
     */
    private String goodInfo;

    /**
     * 商品图片地址
     */
    private String imageUrl;

    /**
     * 商品类型[0:小件,1:中件,3:大件]
     */
    private Integer goodType;

    /**
     * 备注信息
     */
    private String remarkInfo;

    /**
     * 送货地址id
     */
    private String addressId;

    /**
     * 订单状态
     */
    private Integer orderType;

    /**
     * 货物状态
     */
    private Integer processType;

    /**
     * 送达照片
     */
    private String sendGoodImage;


    public static PageData<KdOrderVO> convert(PageData<KdOrderDTO> data) {
        List<KdOrderDTO> dataList = data.getList();
        if (CollUtil.isEmpty(dataList)) {
            return new PageData<>(Collections.emptyList(), data.getPages(), data.getTotal());
        }
        return new PageData<>(dataList.stream().map(KdOrderVO::createItem).collect(Collectors.toList()), data.getPages(), data.getTotal());
    }


    public static KdOrderVO createItem(KdOrderDTO dto) {
        return new KdOrderVO()
                .setOrderId(dto.getOrderId())
                .setBuildingsId(dto.getBuildingsId())
                .setGoodInfo(dto.getGoodInfo())
                .setImageUrl(dto.getImageUrl())
                .setGoodType(dto.getGoodType().getCode())
                .setRemarkInfo(dto.getRemarkInfo())
                .setAddressId(dto.getAddressId())
                .setOrderType(dto.getOrderType().getCode())
                .setProcessType(dto.getProcessType().getCode())
                .setSendGoodImage(dto.getSendGoodImage());
    }
}
